﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using System.Windows.Threading;
using Zeus.Web.Classes;

namespace Zeus
{
    public partial class SoluationControl : UserControl
    {
        private DispatcherTimer doubleClickTimer = new DispatcherTimer();
		private bool doubleClickFlag;
        public SoluationControl()
        {
            InitializeComponent();
            this.doubleClickTimer.Interval = TimeSpan.FromMilliseconds(200);
            this.doubleClickTimer.Tick += new EventHandler(doubleClickTimer_Tick);
            this.treeView1.AddHandler(RadTreeViewItem.MouseLeftButtonDownEvent, new MouseButtonEventHandler(treeView1_MouseLeftButtonDown), true);
            this.FillSolution();
        }
        void treeView1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
		{
			RadTreeViewItem selectedItem = treeView1.SelectedItem as RadTreeViewItem;
			if (selectedItem != null && selectedItem.Items.Count == 0)
			{
				if (this.doubleClickFlag)
				{
					MessageBox.Show(selectedItem.Header.ToString());
				}
				else
				{
					this.doubleClickTimer.Start();
					this.doubleClickFlag = true;
				}
			}
		}
        // The double-click interval has expired, therefore stop the timer and lower the flag
		void doubleClickTimer_Tick(object sender, EventArgs e)
		{
			this.doubleClickTimer.Stop();
			this.doubleClickFlag = false;
		}
        public void FillSolution()
        {
            try
            {
                Project.open(Project.ProjectName);
                for (int i = 0; i < Project.LDocument.Count; i++)
                {
                    RadTreeViewItem Item = new RadTreeViewItem();
                    Item.Header = Project.LDocument[i].FileName;
                    Item.DataContext = 0;
                    switch (Project.LDocument[i].DocType)
                    {
                        case ProjectItem_Types.Code:
                            {
                                App_Code.Items.Add(Item);
                                break;
                            }
                        case ProjectItem_Types.Image:
                            {
                                Images.Items.Add(Item);
                                break;
                            }
                        case ProjectItem_Types.Mesh:
                            {
                                Meshes.Items.Add(Item);
                                break;
                            }
                        case ProjectItem_Types.Sound:
                            {
                                Sounds.Items.Add(Item);
                                break;
                            }
                        case ProjectItem_Types.Scene:
                            {
                                Scenes.Items.Add(Item);
                                break;
                            }
                        case ProjectItem_Types.Video:
                            {
                                Videos.Items.Add(Item);
                                break;
                            }
                        case ProjectItem_Types.Text:
                            {
                                Others.Items.Add(Item);
                                break;
                            }
                    }
                }
            }
            catch(Exception e)
            {}
        }
    }
}